﻿namespace HutongGames.PlayMaker
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using UnityEngine;

    [Serializable]
    public class Fsm : INameable, IComparable//, IPosition
    {
        [CompilerGenerated]
        private Collision CollisionInfo__BackingField;
        [CompilerGenerated]
        private ControllerColliderHit ControllerCollider__BackingField;
        [CompilerGenerated]
        private FsmState EditState__BackingField;
        [CompilerGenerated]
        private FsmEventTarget EventTarget__BackingField;
        [CompilerGenerated]
        private static FsmStateAction ExecutingAction__BackingField;
        [CompilerGenerated]
        private static Fsm ExecutingFsm__BackingField;
        [CompilerGenerated]
        private static FsmState ExecutingState__BackingField;
        [CompilerGenerated]
        private bool HitBreakpoint__BackingField;
        [CompilerGenerated]
        private bool Initialized__BackingField;
        [CompilerGenerated]
        private static bool IsBreak__BackingField;
        [CompilerGenerated]
        private static bool IsErrorBreak__BackingField;
        [CompilerGenerated]
        private bool IsModifiedPrefabInstance__BackingField;
        [CompilerGenerated]
        private static UnityEngine.GameObject LastClickedObject__BackingField;
        [CompilerGenerated]
        private static string LastError__BackingField;
        [CompilerGenerated]
        private FsmTransition LastTransition__BackingField;
        [CompilerGenerated]
        private FsmState PreviousActiveState__BackingField;
        [CompilerGenerated]
        private RaycastHit RaycastHitInfo__BackingField;
        [CompilerGenerated]
        private static Fsm StepFsm__BackingField;
        [CompilerGenerated]
        private static bool StepToStateChange__BackingField;
        [CompilerGenerated]
        private bool SwitchedState__BackingField;
        [CompilerGenerated]
        private Collider TriggerCollider__BackingField;
        [NonSerialized]
        private FsmState activeState;
        private bool activeStateEntered;
        [SerializeField]
        private string activeStateName;
        private static FsmStateAction breakAtAction;
        private static Fsm breakAtFsm;
        private static FsmState breakAtState;
        [SerializeField]
        private bool breakpointsEnabled;
        private static Color debugLookAtColor = Color.grey;
        private static Color debugRaycastColor = Color.grey;
        private readonly List<HutongGames.PlayMaker.DelayedEvent> delayedEvents = new List<HutongGames.PlayMaker.DelayedEvent>();
        [SerializeField]
        private string description = "";
        [SerializeField]
        private string docUrl;
        public bool EnableDebugFlow = true;
        private bool enterStartState;
        public static FsmEventData EventData = new FsmEventData();
        [SerializeField]
        private FsmEvent[] events = new FsmEvent[0];
        public List<FsmEvent> ExposedEvents = new List<FsmEvent>();
        [SerializeField]
        private FsmTransition[] globalTransitions = new FsmTransition[0];
        [SerializeField]
        private int maxReEnterStateCount = 100;
        private FsmLog myLog;
        [SerializeField]
        private string name = "FSM";
        [SerializeField]
        private MonoBehaviour owner;
        private int reEnterStateCount;
        private readonly List<HutongGames.PlayMaker.DelayedEvent> removeEvents = new List<HutongGames.PlayMaker.DelayedEvent>();
        public bool RestartOnEnable = true;
        [SerializeField]
        private bool showStateLabel = true;
        private int startCount;
        [SerializeField]
        private string startState;
        private const string StartStateName = "State 1";
        public static readonly Color[] StateColors = new Color[] { Color.grey, new Color(0.5450981f, 0.6705883f, 0.9411765f), new Color(0.2431373f, 0.7607843f, 0.6901961f), new Color(0.4313726f, 0.7607843f, 0.2431373f), new Color(1f, 0.8745098f, 0.1882353f), new Color(1f, 0.5529412f, 0.1882353f), new Color(0.7607843f, 0.2431373f, 0.2509804f), new Color(0.5450981f, 0.2431373f, 0.7607843f) };
        [SerializeField]
        private FsmState[] states = new FsmState[1];
        private readonly List<HutongGames.PlayMaker.DelayedEvent> updateEvents = new List<HutongGames.PlayMaker.DelayedEvent>();
        [SerializeField]
        private FsmVariables variables = new FsmVariables();
        [SerializeField]
        private string watermark = "";

        public void BroadcastEvent(FsmEvent fsmEvent, [Optional, DefaultParameterValue(false)] bool excludeSelf)
        {
            FsmEventData eventData = NewEventData();
            List<PlayMakerFSM> list = new List<PlayMakerFSM>(PlayMakerFSM.FsmList);
            foreach (PlayMakerFSM rfsm in list)
            {
                if (((rfsm != null) && (rfsm.Fsm != null)) && (!excludeSelf || (rfsm.Fsm != this)))
                {
                    SetEventDataSentBy(eventData);
                    rfsm.Fsm.ChangeState(fsmEvent);
                }
            }
        }

        public void BroadcastEvent(string fsmEventName, [Optional, DefaultParameterValue(false)] bool excludeSelf)
        {
            if (!string.IsNullOrEmpty(fsmEventName))
            {
                this.BroadcastEvent(FsmEvent.GetFsmEvent(fsmEventName), excludeSelf);
            }
        }

        public void BroadcastEventToGameObject(UnityEngine.GameObject go, string fsmEventName, bool sendToChildren, [Optional, DefaultParameterValue(false)] bool excludeSelf)
        {
            if (!string.IsNullOrEmpty(fsmEventName))
            {
                this.BroadcastEventToGameObject(go, FsmEvent.GetFsmEvent(fsmEventName), NewEventData(), sendToChildren, excludeSelf);
            }
        }

        public void BroadcastEventToGameObject(UnityEngine.GameObject go, FsmEvent fsmEvent, FsmEventData eventData, bool sendToChildren, [Optional, DefaultParameterValue(false)] bool excludeSelf)
        {
            if (go != null)
            {
                List<Fsm> list = new List<Fsm>();
                foreach (PlayMakerFSM rfsm in PlayMakerFSM.FsmList)
                {
                    if ((rfsm != null) && (rfsm.gameObject == go))
                    {
                        list.Add(rfsm.Fsm);
                    }
                }
                foreach (Fsm fsm in list)
                {
                    if (!excludeSelf || (fsm != this))
                    {
                        SetEventDataSentBy(eventData);
                        fsm.ChangeState(fsmEvent);
                    }
                }
                if (sendToChildren)
                {
                    for (int i = 0; i < go.transform.childCount; i++)
                    {
                        this.BroadcastEventToGameObject(go.transform.GetChild(i).gameObject, fsmEvent, eventData, true, excludeSelf);
                    }
                }
            }
        }

        public void ChangeState(FsmEvent fsmEvent)
        {
            if ((!FsmEvent.IsNullOrEmpty(fsmEvent) && this.owner.enabled) && this.owner.gameObject.active)
            {
                ExecutingFsm = this;
                if (FsmLog.LoggingEnabled)
                {
                    this.MyLog.LogEvent(fsmEvent, this.activeState);
                }
                foreach (FsmTransition transition in this.globalTransitions)
                {
                    if ((transition.FsmEvent == fsmEvent) && this.DoTransition(transition, true))
                    {
                        return;
                    }
                }
                if (this.ActiveState != null)
                {
                    foreach (FsmTransition transition2 in this.ActiveState.Transitions)
                    {
                        if ((transition2.FsmEvent == fsmEvent) && this.DoTransition(transition2, false))
                        {
                            return;
                        }
                    }
                }
            }
        }

        public int CompareTo(object obj)
        {
            Fsm fsm = obj as Fsm;
            if (fsm != null)
            {
                return this.GuiLabel.CompareTo(fsm.GuiLabel);
            }
            return 0;
        }

        private void Continue()
        {
            this.HitBreakpoint = false;
            IsErrorBreak = false;
            IsBreak = false;
            ExecutingFsm = this;
            ExecutingState = this.ActiveState;
            this.ActiveState.OnEnter();
            this.activeStateEntered = true;
            if (FsmLog.LoggingEnabled)
            {
                this.MyLog.LogEnterState(this.ActiveState);
            }
        }

        public HutongGames.PlayMaker.DelayedEvent DelayedEvent(FsmEvent fsmEvent, float delay)
        {
            HutongGames.PlayMaker.DelayedEvent item = new HutongGames.PlayMaker.DelayedEvent(this, fsmEvent, delay);
            this.delayedEvents.Add(item);
            return item;
        }

        public HutongGames.PlayMaker.DelayedEvent DelayedEvent(FsmEventTarget eventTarget, FsmEvent fsmEvent, float delay)
        {
            HutongGames.PlayMaker.DelayedEvent item = new HutongGames.PlayMaker.DelayedEvent(this, eventTarget, fsmEvent, delay);
            this.delayedEvents.Add(item);
            return item;
        }

        private void DoBreak()
        {
            breakAtFsm = ExecutingFsm;
            breakAtState = ExecutingState;
            breakAtAction = ExecutingAction;
            this.HitBreakpoint = true;
            IsBreak = true;
            if (FsmLog.LoggingEnabled)
            {
                this.MyLog.LogBreak();
            }
            Debug.Break();
            StepToStateChange = false;
        }

        public void DoBreakError(string error)
        {
            IsErrorBreak = true;
            LastError = error;
            this.DoBreak();
        }

        private void DoBreakpoint()
        {
            this.activeStateEntered = false;
            this.DoBreak();
        }

        private bool DoTransition(FsmTransition transition, bool isGlobal)
        {
            FsmState toState = this.GetState(transition.ToState);
            if (toState == null)
            {
                return false;
            }
            this.LastTransition = transition;
            if (Application.isEditor)
            {
                this.MyLog.LogTransition(isGlobal ? null : this.ActiveState, transition);
            }
            this.SwitchState(toState);
            return true;
        }

        public void EnterStartState()
        {
            this.startCount++;
            this.activeState = this.GetState(this.startState);
            if (FsmLog.LoggingEnabled)
            {
                this.MyLog.LogStart(this.activeState);
            }
            if (this.activeState != null)
            {
                this.enterStartState = true;
            }
            else
            {
                this.owner.enabled = false;
                this.MyLog.LogError("Missing Start State!");
            }
        }

        private void EnterState(FsmState state)
        {
            this.EventTarget = null;
            ExecutingState = state;
            this.SwitchedState = true;
            this.ActiveState = state;
            this.reEnterStateCount++;
            if (this.reEnterStateCount > this.maxReEnterStateCount)
            {
                if (FsmLog.LoggingEnabled)
                {
                    this.MyLog.LogWarning("Possible infinite loop!");
                }
            }
            else
            {
                if (FsmLog.LoggingEnabled)
                {
                    this.MyLog.LogEnterState(state);
                }
                state.Fsm = ExecutingFsm;
                state.OnEnter();
            }
            this.activeStateEntered = true;
            this.reEnterStateCount = 0;
        }

        public void Event(FsmEvent fsmEvent)
        {
            if (fsmEvent != null)
            {
                this.Event(this.EventTarget, fsmEvent);
            }
        }

        public void Event(string fsmEventName)
        {
            if (!string.IsNullOrEmpty(fsmEventName))
            {
                this.Event(FsmEvent.GetFsmEvent(fsmEventName));
            }
        }

        public void Event(FsmEventTarget eventTarget, FsmEvent fsmEvent)
        {
            UnityEngine.GameObject ownerDefaultTarget;
            if (eventTarget == null)
            {
                eventTarget = new FsmEventTarget();
            }
            if (FsmLog.LoggingEnabled)
            {
                this.MyLog.LogSendEvent(this.activeState, fsmEvent, eventTarget);
            }
            switch (eventTarget.target)
            {
                case HutongGames.PlayMaker.FsmEventTarget.EventTarget.Self:
                    SetEventDataSentBy();
                    this.ChangeState(fsmEvent);
                    return;

                case HutongGames.PlayMaker.FsmEventTarget.EventTarget.GameObject:
                    ownerDefaultTarget = this.GetOwnerDefaultTarget(eventTarget.gameObject);
                    this.BroadcastEventToGameObject(ownerDefaultTarget, fsmEvent, NewEventData(), eventTarget.sendToChildren.Value, eventTarget.excludeSelf.Value);
                    return;

                case HutongGames.PlayMaker.FsmEventTarget.EventTarget.GameObjectFSM:
                    ownerDefaultTarget = this.GetOwnerDefaultTarget(eventTarget.gameObject);
                    this.SendEventToFsmOnGameObject(ownerDefaultTarget, eventTarget.fsmName.Value, fsmEvent);
                    return;

                case HutongGames.PlayMaker.FsmEventTarget.EventTarget.FSMComponent:
                    if (eventTarget.fsmComponent == null)
                    {
                        break;
                    }
                    SetEventDataSentBy();
                    eventTarget.fsmComponent.Fsm.ChangeState(fsmEvent);
                    return;

                case HutongGames.PlayMaker.FsmEventTarget.EventTarget.BroadcastAll:
                    this.BroadcastEvent(fsmEvent, eventTarget.excludeSelf.Value);
                    break;

                default:
                    return;
            }
        }

        public void Event(FsmEventTarget eventTarget, string fsmEventName)
        {
            if (!string.IsNullOrEmpty(fsmEventName))
            {
                this.Event(eventTarget, FsmEvent.GetFsmEvent(fsmEventName));
            }
        }

        private void ExitState(FsmState state)
        {
            ExecutingState = state;
            if (FsmLog.LoggingEnabled)
            {
                this.MyLog.LogExitState(state);
            }
            this.ActiveState = null;
            state.Fsm = ExecutingFsm;
            state.OnExit();
        }

        public void FixedUpdate()
        {
            ExecutingFsm = this;
            if (this.ActiveState != null)
            {
                FixedUpdateState(this.ActiveState);
            }
        }

        private static void FixedUpdateState(FsmState state)
        {
            ExecutingState = state;
            state.Fsm = ExecutingFsm;
            state.OnFixedUpdate();
        }

        public FsmEvent GetEvent(string eventName)
        {
            if (string.IsNullOrEmpty(eventName))
            {
                return null;
            }
            FsmEvent fsmEvent = FsmEvent.GetFsmEvent(eventName);
            List<FsmEvent> fsmEventList = new List<FsmEvent>(this.events);
            if (!FsmEvent.EventListContainsEvent(fsmEventList, eventName))
            {
                fsmEventList.Add(fsmEvent);
            }
            this.events = fsmEventList.ToArray();
            return fsmEvent;
        }

        public FsmBool GetFsmBool(string varName)
        {
            return this.variables.GetFsmBool(varName);
        }

        public FsmColor GetFsmColor(string varName)
        {
            return this.variables.GetFsmColor(varName);
        }

        public FsmFloat GetFsmFloat(string varName)
        {
            return this.variables.GetFsmFloat(varName);
        }

        public FsmGameObject GetFsmGameObject(string varName)
        {
            return this.variables.GetFsmGameObject(varName);
        }

        public FsmInt GetFsmInt(string varName)
        {
            return this.variables.GetFsmInt(varName);
        }

        public FsmMaterial GetFsmMaterial(string varName)
        {
            return this.variables.GetFsmMaterial(varName);
        }

        public FsmObject GetFsmObject(string varName)
        {
            return this.variables.GetFsmObject(varName);
        }

        public FsmQuaternion GetFsmQuaternion(string varName)
        {
            return this.variables.GetFsmQuaternion(varName);
        }

        public FsmRect GetFsmRect(string varName)
        {
            return this.variables.GetFsmRect(varName);
        }

        public FsmString GetFsmString(string varName)
        {
            return this.variables.GetFsmString(varName);
        }

        public FsmTexture GetFsmTexture(string varName)
        {
            return this.variables.GetFsmTexture(varName);
        }

        public FsmVector3 GetFsmVector3(string varName)
        {
            return this.variables.GetFsmVector3(varName);
        }

        public static string GetFullFsmLabel(Fsm fsm)
        {
            if (fsm == null)
            {
                return "None (FSM)";
            }
            return (fsm.OwnerName + " : " + fsm.Name);
        }

        public UnityEngine.GameObject GetOwnerDefaultTarget(FsmOwnerDefault ownerDefault)
        {
            if (ownerDefault == null)
            {
                return null;
            }
            if (ownerDefault.OwnerOption != OwnerDefaultOption.UseOwner)
            {
                return ownerDefault.GameObject.Value;
            }
            return this.GameObject;
        }

        public FsmState GetState(string stateName)
        {
            foreach (FsmState state in this.states)
            {
                if (state.Name == stateName)
                {
                    return state;
                }
            }
            return null;
        }

        public void GotoPreviousState()
        {
            if (this.PreviousActiveState != null)
            {
                this.SwitchState(this.PreviousActiveState);
            }
        }

        public bool HasEvent(string eventName)
        {
            if (!string.IsNullOrEmpty(eventName))
            {
                foreach (FsmEvent event2 in this.events)
                {
                    if (event2.Name == eventName)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public void Init(MonoBehaviour component)
        {
            this.owner = component;
            if (!Application.isEditor)
            {
                this.breakpointsEnabled = false;
                FsmLog.LoggingEnabled = false;
            }
            this.InitData();
        }

        public void InitData()
        {
            if (!this.Initialized)
            {
                this.Initialized = true;
                for (int i = 0; i < this.events.Length; i++)
                {
                    if (this.events[i] != null)
                    {
                        this.events[i] = FsmEvent.GetFsmEvent(this.events[i]);
                    }
                }
                for (int j = 0; j < this.ExposedEvents.Count; j++)
                {
                    if (this.ExposedEvents[j] != null)
                    {
                        this.ExposedEvents[j] = FsmEvent.GetFsmEvent(this.ExposedEvents[j]);
                    }
                }
                foreach (FsmState state in this.states)
                {
                    state.Fsm = this;
                    state.LoadActions();
                    foreach (FsmTransition transition in state.Transitions)
                    {
                        if (!string.IsNullOrEmpty(transition.EventName))
                        {
                            FsmEvent event2 = this.GetEvent(transition.EventName);
                            transition.FsmEvent = event2;
                        }
                    }
                }
                foreach (FsmTransition transition2 in this.globalTransitions)
                {
                    transition2.FsmEvent = this.GetEvent(transition2.EventName);
                }
            }
        }

        public void LateUpdate()
        {
            ExecutingFsm = this;
            if (this.ActiveState != null)
            {
                LateUpdateState(this.ActiveState);
            }
        }

        private static void LateUpdateState(FsmState state)
        {
            ExecutingState = state;
            state.Fsm = ExecutingFsm;
            state.OnLateUpdate();
        }

        private static FsmEventData NewEventData()
        {
            FsmEventData data2 = new FsmEventData();
            data2.SentByFsm = ExecutingFsm;
            data2.SentByState = ExecutingState;
            data2.SentByAction = ExecutingAction;
            return data2;
        }

        public void OnCollisionEnter(Collision collisionInfo)
        {
            this.CollisionInfo = collisionInfo;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoCollisionEnter(collisionInfo);
                    }
                }
            }
            this.Event(FsmEvent.CollisionEnter);
        }

        public void OnCollisionExit(Collision collisionInfo)
        {
            this.CollisionInfo = collisionInfo;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoCollisionExit(collisionInfo);
                    }
                }
            }
            this.Event(FsmEvent.CollisionExit);
        }

        public void OnCollisionStay(Collision collisionInfo)
        {
            this.CollisionInfo = collisionInfo;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoCollisionStay(collisionInfo);
                    }
                }
            }
            this.Event(FsmEvent.CollisionStay);
        }

        public void OnControllerColliderHit(ControllerColliderHit collider)
        {
            this.ControllerCollider = collider;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoControllerColliderHit(collider);
                    }
                }
            }
            this.Event(FsmEvent.ControllerColliderHit);
        }

        public void OnDestroy()
        {
            if (this.myLog != null)
            {
                this.myLog.OnDestroy();
            }
        }

        public void OnDisable()
        {
            if (this.RestartOnEnable)
            {
                this.Stop();
            }
        }

        public void OnDrawGizmos()
        {
            if (PlayMakerFSM.DrawGizmos)
            {
                Gizmos.DrawIcon(this.owner.transform.position, "PlaymakerIcon.tiff");
            }
            if (this.EditState != null)
            {
                this.EditState.Fsm = this;
                foreach (FsmStateAction action in this.EditState.Actions)
                {
                    action.OnDrawGizmos();
                }
            }
        }

        public void OnDrawGizmosSelected()
        {
            if (this.EditState != null)
            {
                this.EditState.Fsm = this;
                foreach (FsmStateAction action in this.EditState.Actions)
                {
                    action.OnDrawGizmosSelected();
                }
            }
        }

        public void OnEnable()
        {
            this.Start();
        }

        public void OnTriggerEnter(Collider other)
        {
            this.TriggerCollider = other;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoTriggerEnter(other);
                    }
                }
            }
            this.Event(FsmEvent.TriggerEnter);
        }

        public void OnTriggerExit(Collider other)
        {
            this.TriggerCollider = other;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoTriggerExit(other);
                    }
                }
            }
            this.Event(FsmEvent.TriggerExit);
        }

        public void OnTriggerStay(Collider other)
        {
            this.TriggerCollider = other;
            if (this.ActiveState != null)
            {
                foreach (FsmStateAction action in this.ActiveState.Actions)
                {
                    if (action.Active)
                    {
                        action.DoTriggerStay(other);
                    }
                }
            }
            this.Event(FsmEvent.TriggerStay);
        }

        public void Reinitialize()
        {
            this.Initialized = false;
            this.InitData();
        }

        public void Reset(MonoBehaviour component)
        {
            this.owner = component;
            this.name = "FSM";
            this.description = "";
            this.docUrl = "";
            this.globalTransitions = new FsmTransition[0];
            this.events = new FsmEvent[0];
            this.variables = new FsmVariables();
            this.states = new FsmState[1];
            FsmState state = new FsmState(this);
            state.Fsm = this;
            state.Name = "State 1";
            state.Position = new Rect(200f, 200f, 100f, 16f);
            this.States[0] = state;
            this.startState = "State 1";
        }

        public void SendEventToFsmOnGameObject(UnityEngine.GameObject gameObject, string fsmName, FsmEvent fsmEvent)
        {
            if (gameObject != null)
            {
                SetEventDataSentBy();
                List<PlayMakerFSM> list = new List<PlayMakerFSM>(PlayMakerFSM.FsmList);
                if (string.IsNullOrEmpty(fsmName))
                {
                    foreach (PlayMakerFSM rfsm in list)
                    {
                        if (rfsm.gameObject == gameObject)
                        {
                            rfsm.Fsm.ChangeState(fsmEvent);
                        }
                    }
                }
                else
                {
                    foreach (PlayMakerFSM rfsm2 in list)
                    {
                        if ((rfsm2.gameObject == gameObject) && (fsmName == rfsm2.Fsm.Name))
                        {
                            rfsm2.Fsm.ChangeState(fsmEvent);
                            break;
                        }
                    }
                }
            }
        }

        public void SendEventToFsmOnGameObject(UnityEngine.GameObject gameObject, string fsmName, string fsmEventName)
        {
            if (!string.IsNullOrEmpty(fsmEventName))
            {
                this.SendEventToFsmOnGameObject(gameObject, fsmName, FsmEvent.GetFsmEvent(fsmEventName));
            }
        }

        private static void SetEventDataSentBy()
        {
            EventData.SentByFsm = ExecutingFsm;
            EventData.SentByState = ExecutingState;
            EventData.SentByAction = ExecutingAction;
        }

        private static void SetEventDataSentBy(FsmEventData eventData)
        {
            EventData.SentByFsm = eventData.SentByFsm;
            EventData.SentByState = eventData.SentByState;
            EventData.SentByAction = eventData.SentByAction;
        }

        public void Start()
        {
            ExecutingFsm = this;
            ExecutingState = null;
            ExecutingAction = null;
            this.LastTransition = null;
            this.HitBreakpoint = false;
            this.SwitchedState = false;
            if (this.RestartOnEnable && (this.startCount > 0))
            {
                this.EnterStartState();
            }
        }

        public void Stop()
        {
            ExecutingFsm = this;
            if (this.ActiveState != null)
            {
                this.ExitState(this.ActiveState);
            }
            this.LastTransition = null;
            this.SwitchedState = false;
            this.HitBreakpoint = false;
        }

        private void SwitchState(FsmState toState)
        {
            if (toState != null)
            {
                if (this.ActiveState != null)
                {
                    this.PreviousActiveState = this.ActiveState;
                    this.ExitState(this.ActiveState);
                }
                if ((this.breakpointsEnabled && toState.IsBreakpoint) || (StepToStateChange && ((StepFsm == null) || (StepFsm == this))))
                {
                    ExecutingState = toState;
                    this.ActiveState = toState;
                    this.DoBreakpoint();
                }
                else
                {
                    this.EnterState(toState);
                }
            }
        }

        public void Update()
        {
            FsmTime.RealtimeBugFix();
            if (this.owner != null)
            {
                ExecutingFsm = this;
                ExecutingState = null;
                ExecutingAction = null;
                if (!this.HitBreakpoint)
                {
                    if (this.enterStartState)
                    {
                        this.EnterState(this.activeState);
                        this.enterStartState = false;
                    }
                    if (!this.activeStateEntered)
                    {
                        this.Continue();
                    }
                    this.UpdateDelayedEvents();
                    if (this.ActiveState != null)
                    {
                        UpdateState(this.ActiveState);
                    }
                }
            }
        }

        public void UpdateDelayedEvents()
        {
            this.removeEvents.Clear();
            this.updateEvents.Clear();
            this.updateEvents.AddRange(this.delayedEvents);
            foreach (HutongGames.PlayMaker.DelayedEvent event2 in this.updateEvents)
            {
                event2.Update();
                if (event2.Finished)
                {
                    this.removeEvents.Add(event2);
                }
            }
            foreach (HutongGames.PlayMaker.DelayedEvent event3 in this.removeEvents)
            {
                this.delayedEvents.Remove(event3);
            }
        }

        private static void UpdateState(FsmState state)
        {
            ExecutingState = state;
            state.Fsm = ExecutingFsm;
            state.OnUpdate();
        }

        public bool Active
        {
            get
            {
                return ((((this.owner != null) && this.owner.enabled) && (this.owner.gameObject != null)) && this.owner.gameObject.active);
            }
        }

        public FsmState ActiveState
        {
            get
            {
                if ((this.activeState == null) && (this.activeStateName != ""))
                {
                    this.activeState = this.GetState(this.activeStateName);
                }
                return this.activeState;
            }
            private set
            {
                this.activeState = value;
                this.activeStateName = (this.activeState == null) ? "" : this.activeState.Name;
            }
        }

        public string ActiveStateName
        {
            get
            {
                return this.activeStateName;
            }
        }

        public static FsmStateAction BreakAtAction
        {
            get
            {
                return (breakAtAction ?? ExecutingAction);
            }
        }

        public static Fsm BreakAtFsm
        {
            get
            {
                return (breakAtFsm ?? ExecutingFsm);
            }
        }

        public static FsmState BreakAtState
        {
            get
            {
                return (breakAtState ?? ExecutingState);
            }
        }

        public bool BreakpointsEnabled
        {
            get
            {
                return this.breakpointsEnabled;
            }
            set
            {
                this.breakpointsEnabled = value;
            }
        }

        public Collision CollisionInfo
        {
            [CompilerGenerated]
            get
            {
                return this.CollisionInfo__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.CollisionInfo__BackingField = value;
            }
        }

        public ControllerColliderHit ControllerCollider
        {
            [CompilerGenerated]
            get
            {
                return this.ControllerCollider__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.ControllerCollider__BackingField = value;
            }
        }

        public static Color DebugLookAtColor
        {
            get
            {
                return debugLookAtColor;
            }
            set
            {
                debugLookAtColor = value;
            }
        }

        public static Color DebugRaycastColor
        {
            get
            {
                return debugRaycastColor;
            }
            set
            {
                debugRaycastColor = value;
            }
        }

        public List<HutongGames.PlayMaker.DelayedEvent> DelayedEvents
        {
            get
            {
                return this.delayedEvents;
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                this.description = value;
            }
        }

        public string DocUrl
        {
            get
            {
                return this.docUrl;
            }
            set
            {
                this.docUrl = value;
            }
        }

        public FsmState EditState
        {
            [CompilerGenerated]
            get
            {
                return this.EditState__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.EditState__BackingField = value;
            }
        }

        public FsmEvent[] Events
        {
            get
            {
                return this.events;
            }
            set
            {
                this.events = value;
            }
        }

        public FsmEventTarget EventTarget
        {
            [CompilerGenerated]
            get
            {
                return this.EventTarget__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.EventTarget__BackingField = value;
            }
        }

        public static FsmStateAction ExecutingAction
        {
            [CompilerGenerated]
            get
            {
                return ExecutingAction__BackingField;
            }
            [CompilerGenerated]
            set
            {
                ExecutingAction__BackingField = value;
            }
        }

        public static Fsm ExecutingFsm
        {
            [CompilerGenerated]
            get
            {
                return ExecutingFsm__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                ExecutingFsm__BackingField = value;
            }
        }

        public static FsmState ExecutingState
        {
            [CompilerGenerated]
            get
            {
                return ExecutingState__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                ExecutingState__BackingField = value;
            }
        }

        public static List<Fsm> FsmList
        {
            get
            {
                List<Fsm> list = new List<Fsm>();
                foreach (PlayMakerFSM rfsm in PlayMakerFSM.FsmList)
                {
                    if ((rfsm != null) && (rfsm.Fsm != null))
                    {
                        list.Add(rfsm.Fsm);
                    }
                }
                return list;
            }
        }

        public UnityEngine.GameObject GameObject
        {
            get
            {
                if (this.Owner == null)
                {
                    return null;
                }
                return this.Owner.gameObject;
            }
        }

        public string GameObjectName
        {
            get
            {
                if (this.Owner == null)
                {
                    return "[missing GameObject]";
                }
                return this.Owner.gameObject.name;
            }
        }

        public FsmTransition[] GlobalTransitions
        {
            get
            {
                return this.globalTransitions;
            }
            set
            {
                this.globalTransitions = value;
            }
        }

        private string GuiLabel
        {
            get
            {
                return (this.OwnerName + " : " + this.Name);
            }
        }

        public bool HitBreakpoint
        {
            [CompilerGenerated]
            get
            {
                return this.HitBreakpoint__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.HitBreakpoint__BackingField = value;
            }
        }

        public bool Initialized
        {
            [CompilerGenerated]
            get
            {
                return this.Initialized__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.Initialized__BackingField = value;
            }
        }

        public static bool IsBreak
        {
            [CompilerGenerated]
            get
            {
                return IsBreak__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                IsBreak__BackingField = value;
            }
        }

        public static bool IsErrorBreak
        {
            [CompilerGenerated]
            get
            {
                return IsErrorBreak__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                IsErrorBreak__BackingField = value;
            }
        }

        public bool IsModifiedPrefabInstance
        {
            [CompilerGenerated]
            get
            {
                return this.IsModifiedPrefabInstance__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.IsModifiedPrefabInstance__BackingField = value;
            }
        }

        public static UnityEngine.GameObject LastClickedObject
        {
            [CompilerGenerated]
            get
            {
                return LastClickedObject__BackingField;
            }
            [CompilerGenerated]
            set
            {
                LastClickedObject__BackingField = value;
            }
        }

        public static string LastError
        {
            [CompilerGenerated]
            get
            {
                return LastError__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                LastError__BackingField = value;
            }
        }

        public FsmTransition LastTransition
        {
            [CompilerGenerated]
            get
            {
                return this.LastTransition__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.LastTransition__BackingField = value;
            }
        }

        public int MaxReEnterStateCount
        {
            set
            {
                this.maxReEnterStateCount = value;
            }
        }

        public FsmLog MyLog
        {
            get
            {
                return (this.myLog ?? (this.myLog = FsmLog.GetLog(this)));
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        public MonoBehaviour Owner
        {
            get
            {
                return this.owner;
            }
            set
            {
                this.owner = value;
            }
        }

        public string OwnerDebugName
        {
            get
            {
                if (this.owner == null)
                {
                    return "[missing Owner]";
                }
                return this.owner.name;
            }
        }

        public string OwnerName
        {
            get
            {
                if (this.owner == null)
                {
                    return "";
                }
                return this.owner.name;
            }
        }

        public FsmState PreviousActiveState
        {
            [CompilerGenerated]
            get
            {
                return this.PreviousActiveState__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.PreviousActiveState__BackingField = value;
            }
        }

        public RaycastHit RaycastHitInfo
        {
            [CompilerGenerated]
            get
            {
                return this.RaycastHitInfo__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.RaycastHitInfo__BackingField = value;
            }
        }

        public bool ShowStateLabel
        {
            get
            {
                return this.showStateLabel;
            }
            set
            {
                this.showStateLabel = value;
            }
        }

        public static List<Fsm> SortedFsmList
        {
            get
            {
                List<Fsm> fsmList = FsmList;
                fsmList.Sort();
                return fsmList;
            }
        }

        public string StartState
        {
            get
            {
                return this.startState;
            }
            set
            {
                this.startState = value;
            }
        }

        public FsmState[] States
        {
            get
            {
                return this.states;
            }
            set
            {
                this.states = value;
            }
        }

        public static Fsm StepFsm
        {
            [CompilerGenerated]
            get
            {
                return StepFsm__BackingField;
            }
            [CompilerGenerated]
            set
            {
                StepFsm__BackingField = value;
            }
        }

        public static bool StepToStateChange
        {
            [CompilerGenerated]
            get
            {
                return StepToStateChange__BackingField;
            }
            [CompilerGenerated]
            set
            {
                StepToStateChange__BackingField = value;
            }
        }

        public bool SwitchedState
        {
            [CompilerGenerated]
            get
            {
                return this.SwitchedState__BackingField;
            }
            [CompilerGenerated]
            set
            {
                this.SwitchedState__BackingField = value;
            }
        }

        public Collider TriggerCollider
        {
            [CompilerGenerated]
            get
            {
                return this.TriggerCollider__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.TriggerCollider__BackingField = value;
            }
        }

        public FsmVariables Variables
        {
            get
            {
                return this.variables;
            }
            set
            {
                this.variables = value;
            }
        }

        public string Watermark
        {
            get
            {
                return this.watermark;
            }
            set
            {
                this.watermark = value;
            }
        }

        //[SerializeField]
        //private Rect position = new Rect(0, 0, 100, 50);

        //public Rect Position
        //{
        //    get
        //    {
        //        return position;
        //    }
        //    set
        //    {
        //        position = value;
        //    }
        //}
    }
}

